﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DFGK.Service
{
    public class StocktakeResultRecordService : BaseService, IStocktakeResultRecordService
    {
        private readonly IStocktakeResultRecordRepository _stocktakeResultRecordRepository;
        public StocktakeResultRecordService(IMapper mapper, IStocktakeResultRecordRepository _stocktakeResultRecordRepository) : base(mapper)
        {
            this._stocktakeResultRecordRepository = _stocktakeResultRecordRepository;
        }

        public List<StocktakeResultRecord> GetStocktakeResultRecordList(string? ordersn, string? materialkey, int? status, byte? isHandle, int pageIndex, int pageSize, out int totalCount)
        {
            var slist = _stocktakeResultRecordRepository.GetEntityAlls();

            if (!string.IsNullOrEmpty(ordersn))
                slist = slist.Where(x => x.OrderSn.Contains(ordersn));
            if (status != null)
                slist = slist.Where(x => x.Status == status);

            if (isHandle != null)
                slist = slist.Where(x => x.IsHandle == isHandle);

            if (!string.IsNullOrEmpty(materialkey))
                slist = slist.Where(x => x.MaterialName.Contains(materialkey));

            var list = _stocktakeResultRecordRepository.GetEntityAlls(slist, pageIndex, pageSize, out totalCount, x => x.CreateDate, false);
            return list.ToList();
        }
    }
}
